package com.elitel.frame.web.cfgsiminfo.controller;

import com.elitel.common.utils.SpringUtils;
import com.elitel.frame.main.entity.vo.JsonResult;
import com.elitel.frame.task.SyncServiceInterfaceConfigScheduler;
import com.elitel.frame.web.cfgsiminfo.entity.CfgSimInfo;
import com.elitel.frame.web.cfgsiminfo.entity.CfgSimInfoDTO;
import com.elitel.frame.web.cfgsiminfo.service.CfgSimInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author mulis
 */
@RestController
@RequestMapping("/cfgsiminfo")
public class CfgSimInfoController {
    @Resource
    private CfgSimInfoService cfgSimInfoService;



    @RequestMapping("/copyParamList")
    public JsonResult copyParamList() {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setSuccess(true);
        cfgSimInfoService.copyParamList();
        return jsonResult;
    }

    @RequestMapping("/deleteByPrimaryKey")
    public JsonResult deleteByPrimaryKey(String infoId) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(cfgSimInfoService.deleteByPrimaryKey(infoId));
        jsonResult.setSuccess(true);
        return jsonResult;
    }


    @GetMapping("/selectByServiceId")
    public JsonResult selectByServiceId(String serviceId) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(cfgSimInfoService.selectByServiceId(serviceId));
        jsonResult.setSuccess(true);
        return jsonResult;
    }


    @GetMapping("/selectList")
    public JsonResult selectList(CfgSimInfo cfgSimInfo) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(cfgSimInfoService.selectList(cfgSimInfo));
        jsonResult.setSuccess(true);
        return jsonResult;
    }


    @PostMapping("/save")
    public JsonResult save(@RequestBody CfgSimInfoDTO dto) {
        JsonResult jsonResult = new JsonResult();
        try {
            jsonResult.setData(cfgSimInfoService.save(dto));
            try {
                SpringUtils.getBean(SyncServiceInterfaceConfigScheduler.class).syncData();
            } catch (Exception e) {
            }
            jsonResult.setSuccess(true);
        } catch (Exception e) {
            jsonResult.setSuccess(false);
            jsonResult.setMsg(e.getMessage());
        }
        return jsonResult;
    }


}
